//
// Created by ZhangKewei on 2019/12/25.
//

#include <stdio.h>
#include "sysinfo.h"
#include "procps.h"
#include "getsysinfo.h"


int io_cnt(unsigned int *rw_num, unsigned long long *rw_bytes) {

    unsigned int cDisk = 0;
    disk_stat *disks[100];//= malloc(sizeof(disk_stat));
    partition_stat *partitions[100];
    int i = 0;
    /*
      读写次数 = 读完成次数(reads) + 合并读完成次数(merged_reads) +
                   写完成次数(writes)  + 合并写完成次数(merged_writes)
       读写字节数 = (读扇区次数(read_sectors)  +
                    写扇区次数( written_sectors) ) / 2
    */
    cDisk = getdiskstat(disks, partitions);

    for (i = 0; i < cDisk; ++i) {
        if (*((*disks + i)->disk_name) == 's') {
            *rw_num += (*disks + i)->reads + (*disks + i)->merged_reads + (*disks + i)->writes +
                       (*disks + i)->merged_writes;
            *rw_bytes += (*disks + i)->reads_sectors + (*disks + i)->written_sectors;
        }
    }

}